package com.qf.shop.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qf.shop.entity.Orders;
import com.qf.shop.entity.ProcessLog;
import com.qf.shop.mapper.ProcessLogMapper;
import com.qf.shop.model.TableData;
import com.qf.shop.pojo.QueryProcess;
import com.qf.shop.service.IProcessLogService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProcessLogImpl implements IProcessLogService {

    private ProcessLogMapper processLogMapper;

    public ProcessLogImpl(ProcessLogMapper processLogMapper) {
        this.processLogMapper = processLogMapper;
    }

    @Override
    public TableData<ProcessLog> getAllProcess(QueryProcess queryProcess, Integer offset, Integer limit) {
        String orderName = queryProcess.getOrderName();
        if(null != orderName && !"".equals(orderName.trim())) {

            queryProcess.setOrderName("%" + orderName + "%");
        }

        String OrderDes = queryProcess.getOrderDes();
        if(null != OrderDes && !"".equals(OrderDes.trim())) {

            queryProcess.setOrderDes("%" + OrderDes + "%");

        }

        String orderMethod = queryProcess.getOrderMethod();

        if(null != orderMethod && !"".equals(orderMethod.trim())) {

            queryProcess.setOrderMethod("%" + orderMethod + "%");

        }

        String orderClass = queryProcess.getOrderClass();

        if(null != orderClass && !"".equals(orderClass.trim())) {

            queryProcess.setOrderClass("%" + orderClass + "%");

        }


        Page<ProcessLog> page = PageHelper.offsetPage(offset, limit);

        List<ProcessLog> allProcess = processLogMapper.getAllProcess(queryProcess);

        System.out.println(allProcess.toString());

        TableData<ProcessLog> tableData = new TableData<>();
        tableData.setRows(page.getResult());
        tableData.setTotal(page.getTotal());

        return tableData;
    }
}
